using System;
using System.Windows.Forms;
using System.Windows.Input;
using ScriptEase.Shell.Controls;
using ScriptEase.Shell.Events;



namespace ScriptEase.Shell.Commands
{
    internal class ProjectEditCommand : ICommand
    {
        private readonly ShellViewModel _viewViewModel;



        public ProjectEditCommand(ShellViewModel viewViewModel)
        {
            _viewViewModel = viewViewModel;
        }



        public void Execute(object view)
        {
            MessageBox.Show("Project setting changes will become active after re-opening the project!", "Project Settings", MessageBoxButtons.OK, MessageBoxIcon.Information);
            ProjectConfigurationEditor e = new ProjectConfigurationEditor();
            e.SetConfig(_viewViewModel.Project.Data);

            var result = e.ShowDialog(view as Form);
            if (result != DialogResult.OK) return;

            e.GetConfig(_viewViewModel.Project.Data);
            Project.SaveToFile(_viewViewModel.Project.Data);
        }



        public bool CanExecute(object parameter)
        {
            return _viewViewModel.ProjectLoadStatus == ProjectStatus.LoadedDisconnected || _viewViewModel.ProjectLoadStatus == ProjectStatus.Connected;
        }



        public event EventHandler CanExecuteChanged;
    }
}